# -*- coding: utf-8 -*-
# @Time     : 2021/11/27 16:08
# @Author   : wljess
# @File     : 基于生成器的上下文管理器.py
# @Describe : 
# @Software : PyCharm

from contextlib import contextmanager


@contextmanager
def file_manager(name, mode):
    try:
        f = open(name, mode)
        yield f
    except Exception as error:
        print(type(error))
        print(error)
    finally:
        f.close()


with file_manager("info.txt", "r") as file:
    content = file.read()
    print(content)
